package com.example.byteinputstream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class ByteStreamDemo8 {
    public static void main(String[] args) throws FileNotFoundException {
        //创建对象
        FileInputStream fis = new FileInputStream("src/com/example/file/a.txt");
        FileOutputStream fos = new FileOutputStream("src/com/example/file/b.txt");
        /**
         * 自动释放资源
         */
        try (fis; fos) {
            //拷贝文件
            byte[] buf = new byte[1024];
            int read = fis.read(buf);
            while (read != -1) {
                fos.write(buf, 0, read);
                read = fis.read(buf);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
